﻿package mortal.common
{
    import com.gengine.manager.*;
    import flash.events.*;
    import flash.net.*;
    import mortal.common.global.*;
    import mortal.game.manager.*;

    public class PulseSharedObject extends Object
    {
        private static const Pulse_NotTip:String = "pulse/Pulse_NotTip";
        private static var _userDataObj:Object;
        private static var _sharedObject:SharedObject;
        private static var _isCache:Boolean = true;

        public function PulseSharedObject()
        {
            return;
        }// end function

        public static function save(param1:String, param2:Boolean) : void
        {
            if (_isCache == false)
            {
                return;
            }
            var _loc_3:* = ParamsConst.instance.username;
            var _loc_4:* = ClockManager.instance.nowDate;
            if (param2 == false)
            {
                _loc_4 = null;
            }
            getSharedObject();
            _userDataObj[_loc_3 + "_" + param1] = _loc_4;
            _sharedObject.data.userDataObj = _userDataObj;
            return;
        }// end function

        public static function isTodayNotTips(param1:String) : Boolean
        {
            var _loc_4:Date = null;
            if (_isCache == false)
            {
                return false;
            }
            var _loc_2:* = ParamsConst.instance.username;
            var _loc_3:* = ClockManager.instance.nowDate;
            getSharedObject();
            if (_userDataObj[_loc_2 + "_" + param1])
            {
                _loc_4 = _userDataObj[_loc_2 + "_" + param1] as Date;
                if (_loc_4 != null && _loc_4.date == _loc_3.date && _loc_4.month == _loc_3.month && _loc_4.fullYear == _loc_3.fullYear)
                {
                    return true;
                }
            }
            return false;
        }// end function

        public static function saveValue(param1:String, param2:Object) : void
        {
            if (_isCache == false)
            {
                return;
            }
            var _loc_3:* = ParamsConst.instance.username;
            getSharedObject();
            _userDataObj[_loc_3 + "_" + param1] = param2;
            _sharedObject.data.userDataObj = _userDataObj;
            return;
        }// end function

        public static function getValue(param1:String) : Object
        {
            var _loc_2:* = ParamsConst.instance.username;
            getSharedObject();
            return _userDataObj[_loc_2 + "_" + param1];
        }// end function

        private static function getSharedObject() : void
        {
            if (_sharedObject == null)
            {
                _sharedObject = CacheManager.instance.getLocal(Pulse_NotTip);
                _sharedObject.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusEvent);
            }
            if (_userDataObj == null)
            {
                _userDataObj = _sharedObject.data.userDataObj;
                if (_userDataObj == null)
                {
                    _userDataObj = {};
                }
            }
            return;
        }// end function

        private static function onNetStatusEvent(event:NetStatusEvent) : void
        {
            if (event.info.code == "SharedObject.Flush.Failed")
            {
                _isCache = false;
            }
            else
            {
                _isCache = true;
            }
            return;
        }// end function

    }
}
